package com.itlong.cloud.property.service.impl;

import com.itlong.cloud.POJO.DTO.operate.ParkingRecordPageDTO;
import com.itlong.cloud.POJO.DTO.property.ParkPlaceProjectInfoDTO;
import com.itlong.cloud.POJO.VO.property.PropertyTemporaryCarFeeRecordVO;
import com.itlong.cloud.property.dao.IPropertyParkingPassRecordDao;
import com.itlong.cloud.property.service.IPropertyParkingPassRecordService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业-智慧停车-停车场出入记录接口实现类.
 * </desc>
 *
 * @createDate 2018/11/5
 */
@Service
public class PropertyParkingPassRecordServiceImpl implements IPropertyParkingPassRecordService {

    @Autowired
    IPropertyParkingPassRecordDao iPropertyParkingPassRecordDao;

    /**
     * <desc>
     *      停车场入场记录分页查询
     * <desc/>
     *
     * @param parkingRecordPageDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @Override
    public Page<PropertyTemporaryCarFeeRecordVO> getAdmissionRecordPage(ParkingRecordPageDTO parkingRecordPageDTO) throws Exception {
        //将DTO转换为Map
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(parkingRecordPageDTO);
        //分页默认pageSize为20
        Page<PropertyTemporaryCarFeeRecordVO> page = new Page<>();
        page.getPage().setPageSize(parkingRecordPageDTO.getPageSize());
        page.getPage().setCurrentPage(parkingRecordPageDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        List<PropertyTemporaryCarFeeRecordVO> list = iPropertyParkingPassRecordDao.getAdmissionRecordPage(params);
        Integer count = iPropertyParkingPassRecordDao.getAdmissionRecordCount(params);
        page.setRows(list,count);
        return page;
    }

    /**
     * <desc>
     *      停车场出场记录分页查询
     * <desc/>
     *
     * @param parkingRecordPageDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @Override
    public Page<PropertyTemporaryCarFeeRecordVO> getAppearanceRecordPage(ParkingRecordPageDTO parkingRecordPageDTO) throws Exception {
        //将DTO转换为Map
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(parkingRecordPageDTO);
        //分页默认pageSize为20
        Page<PropertyTemporaryCarFeeRecordVO> page = new Page<>();
        page.getPage().setPageSize(parkingRecordPageDTO.getPageSize());
        page.getPage().setCurrentPage(parkingRecordPageDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        List<PropertyTemporaryCarFeeRecordVO> list = iPropertyParkingPassRecordDao.getAppearanceRecordPage(params);
        Integer count = iPropertyParkingPassRecordDao.getAppearanceRecordCount(params);
        page.setRows(list,count);
        return page;
    }

    /**
     * <desc>
     *      获取当前开通了停车场的项目信息
     * </desc>
     *
     * @author Jiaqi.X
     * @createDate 2018/11/08
     */
    @Override
    public List<ParkPlaceProjectInfoDTO> getInStatusProjectIds() {
        return iPropertyParkingPassRecordDao.getInStatusProjectIds();
    }

    /**
     * <desc>
     *      获取项目下处于入场状态下的所有parkingId
     * </desc>
     *
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/11/08
     */
    @Override
    public List<String> getInStatusParkingIdByProjectId(String projectId) {
        return iPropertyParkingPassRecordDao.getInStatusParkingIdByProjectId(projectId);
    }

    /**
     * <desc>
     *      获取项目下处于入场状态下的所有车牌号
     * </desc>
     *
     * @param projectId
     * @return
     * @createDate 2018/11/08
     * @author Jiaqi.X
     */
    @Override
    public List<String> getInPlantNoByProjectId(String projectId){
        return iPropertyParkingPassRecordDao.getInPlantNoByProjectId(projectId);
    }

    /**
     * <desc>
     *     获取项目停车场的key
     * </desc>
     *
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/11/08
     */
    @Override
    public String getParkingLotKey(String projectId) {
        return iPropertyParkingPassRecordDao.getParkingLotKey(projectId);
    }
}